/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-31
 * Time: 15:04
 */
public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        Object object=new Object();
        Object object2=new Object();

        Thread t1=new Thread(()->{
            synchronized (object){
                System.out.println("t1 等待之前");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 等待之后");
            }
        });
        Thread t2=new Thread(()->{
            synchronized (object){
                System.out.println("t2 等待之前");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2 等待之后");
            }
        });

        Thread t4=new Thread(()->{
            synchronized (object2){
                System.out.println("t4 等待之前");
                try {
                    object2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t4 等待之后");
            }
        });
        Thread t3=new Thread(()->{
            synchronized (object){
                System.out.println("t3 通知之前");
                object.notifyAll();//唤醒所有的因object锁引起的阻塞等待,但t4线程不会被唤醒
                System.out.println("t3 通知之后");
            }
        });



        t1.start();
        t2.start();
        t4.start();
        Thread.sleep(1000);
        t3.start();

    }
}
